package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.SysRoleUserMapper;
import com.atguigu.spzx.manager.service.SysRoleUserService;
import com.atguigu.spzx.model.dto.system.AssignRoleDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysRoleUserServiceImpl implements SysRoleUserService {
    @Autowired
    private SysRoleUserMapper sysRoleUserMapper;

    @Override
    public void doAssign(AssignRoleDto assignRoleDto) {
        // 删除之前用户所对应的所有角色信息
        sysRoleUserMapper.deleteByUserId(assignRoleDto.getUserId());

        // 请求分配的角色列表是否为空
        List<Long> roleIdList = assignRoleDto.getRoleIdList();
        if(roleIdList.isEmpty()) return;

        sysRoleUserMapper.doAssign(assignRoleDto);
    }
}
